import 'package:inmotion_pro/pages/mixin/check_mixin.dart';
import 'package:inmotion_pro/service/global_service.dart';
import 'package:lx_widgets_library/utils/share_preferences_util.dart';

// 网络配置相关
class AreaHelper with CheckMixin {
  // http默认的Area
  static const String _httpDefaultArea = "us-dev";

  // wss默认的Area
  static const String _wssDefaultArea = "us-nc";

  // 本地保存用户Area的key
  static String get _localAreaKey {
    final int uid = GlobalService.to.cacheUserInfo.value.uid;
    return '${uid}_user_area';
  }

  // 保存http Area
  static Future<void> saveHttpArea(String area) async {
    await SharedPreferencesService.to.setString(_localAreaKey, area);
  }

  // 获取http Area
  static String get httpArea {
    return SharedPreferencesService.to.getString(_localAreaKey) ??
        _httpDefaultArea;
  }

  // 获取wss url
  static String get wssUrl {
    final area = SharedPreferencesService.to.getString(_localAreaKey);
    return "wss://api.${area ?? _wssDefaultArea}.imscv.com/v2/ws";
  }
}
